package com.lwx.es.model;

import java.io.IOException;
import java.util.Map;

import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

public class ESModelImpl implements IESModel {

	private String docId;

	private Map<String, Object> data;

//	private String json;


	public String getDocId() {
		return this.docId;
	}

	public Map<String, Object> getData() {
		return this.data;
	}

	public String getJson() throws IOException {
		
		XContentBuilder builder = XContentFactory.jsonBuilder().startObject();

		for (Map.Entry<String, Object> e : this.data.entrySet()) {
		    builder.field(e.getKey(), e.getValue());
		}
		builder.endObject();
		return builder.string();
	}

	public void setDocId(String docId) {
		this.docId = docId;
	}

	public void setData(Map<String, Object> data) {
		this.data = data;
	}

}
